<?php
namespace Services;
/**
 * File holds class for Type data manipulation
 *
 * PHP version 5.3.5
 *
 * @category   CM
 * @package    Services
 * @subpackage -
 * @author     markus karileet <markuskarileet@hotmail.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @link       -
 */
class Type extends ORM {
	/**
	 * Method returns all types from database
	 * @return array Array of types
	 * @throws \Exception when database transaction fails
	 */
	public function getAllTypes() {
		$t = new \Entities\Type();
		$types = $this->selectMulti($t);
		return $types;
	}
	
	/**
	 * Method returns types that have connected business
	 * @return array Array of types
	 * @throws \Exception when database transaction fails
	 */
	public function getActiveTypes() {
		$sql = 'SELECT DISTINCT(t.id), t.`name` '
		. 'FROM type t, business b '
		. 'WHERE b.id > 0 AND b.type = t.id '
		. 'GROUP BY t.id ORDER BY t.id ASC';
		$types = $this->rawQuery($sql, new \Entities\Type());
		return $types;
	}
}